home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 August / CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso / disc2 / programr / atre27.exe / ATREE_27 / LFWIN / WINSYNAN.C < prev    next >
C/C++ Source or Header  |  1992-08-01  |  49KB  |  1,742 lines

  1.  
  2. /*  A Bison parser, made from winsynan.y  */
  3.  
  4. #define    FUNCTION    258
  5. #define    DOMAINS    259
  6. #define    CODOMAINS    260
  7. #define    DIMENSIONS    261
  8. #define    EQUALS    262
  9. #define    INTEGER    263
  10. #define    QUANTIZATION    264
  11. #define    COLON    265
  12. #define    TRAINING    266
  13. #define    SET    267
  14. #define    _SIZE    268
  15. #define    TEST    269
  16. #define    CODING    270
  17. #define    LARGEST    271
  18. #define    SMALLEST    272
  19. #define    REAL    273
  20. #define    TREE    274
  21. #define    MIN    275
  22. #define    MAX    276
  23. #define    CORRECT    277
  24. #define    EPOCHS    278
  25. #define    VOTE    279
  26. #define    IDENTIFIER    280
  27. #define    STRING    281
  28. #define    SAVE    282
  29. #define    TO    283
  30. #define    LOAD    284
  31. #define    FROM    285
  32. #define    FOLDED    286
  33.  
  34. #line 1 "winsynan.y"
  35.  
  36. /*****************************************************************************
  37.  ****                                                                     ****
  38.  **** winsynan.y                                                          ****
  39.  ****                                                                     ****
  40.  **** atree release 2.7 for Windows                                       ****
  41.  **** Adaptive Logic Network (ALN) simulation program.                    ****
  42.  **** Copyright (C) A. Dwelly, R. Manderscheid, M. Thomas, W.W. Armstrong ****
  43.  ****               1991, 1992                                            ****
  44.  ****                                                                     ****
  45.  **** License:                                                            ****
  46.  **** A royalty-free license is granted for the use of this software for  ****
  47.  **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or     ****
  48.  **** modified provided this notice appears in its entirety and unchanged ****
  49.  **** in all derived source programs.  Persons modifying the code are     ****
  50.  **** requested to state the date, the changes made and who made them     ****
  51.  **** in the modification history.                                        ****
  52.  ****                                                                     ****
  53.  **** Patent License:                                                     ****
  54.  **** The use of a digital circuit which transmits a signal indicating    ****
  55.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  56.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  57.  **** W. W. Armstrong, President.  A royalty-free license is granted      ****
  58.  **** by the company to use this patent for NON_COMMERCIAL PURPOSES to    ****
  59.  **** adapt logic trees using this program and its modifications.         ****
  60.  ****                                                                     ****
  61.  **** Limited Warranty:                                                   ****
  62.  **** This software is provided "as is" without warranty of any kind,     ****
  63.  **** either expressed or implied, including, but not limited to, the     ****
  64.  **** implied warrantees of merchantability and fitness for a particular  ****
  65.  **** purpose.  The entire risk as to the quality and performance of the  ****
  66.  **** program is with the user.  Neither the authors, nor the             ****
  67.  **** University of Alberta, its officers, agents, servants or employees  ****
  68.  **** shall be liable or responsible in any way for any damage to         ****
  69.  **** property or direct personal or consequential injury of any nature   ****
  70.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  71.  **** or any other party as a consequence of the use or disposition of    ****
  72.  **** this software.                                                      ****
  73.  **** Modification history:                                               ****
  74.  ****                                                                     ****
  75.  **** 90.02.10 Initial implementation, A.Dwelly                           ****
  76.  **** 91.07.15 Release 2, Rolf Manderscheid                               ****
  77.  **** 91.07.15 Windows Port, M. Thomas                                    ****
  78.  **** 92.04.27 atree v2.5, M. Thomas                                      ****
  79.  **** 92.03.07 Release 2.6, Monroe Thomas                                 ****
  80.  **** 92.01.08 Release 2.7, Monroe Thomas                                 ****
  81.  ****                                                                     ****
  82.  *****************************************************************************/
  83.  
  84. #include "atree.h"
  85. #include "lf.h"
  86.  
  87. extern BOOL train_size_flag;
  88. extern BOOL test_size_flag;
  89. extern BOOL largest_flag;
  90. extern BOOL smallest_flag;
  91. extern BOOL fold_flag;
  92. extern BOOL code_flag;
  93. extern BOOL quant_flag;
  94. extern prog_t prog;
  95.  
  96. FILE *yyin;
  97. int line_no;
  98.  
  99. static BOOL first = TRUE;
  100. static int tuple_ptr;
  101. static int table_ptr;
  102. static int table_size;
  103. extern float far * far *tmp_table;
  104. char szBuffer[120];
  105.  
  106. void
  107. yyerrexit()
  108. {
  109.     int i;
  110.  
  111.     first = TRUE;
  112.  
  113.     if (tmp_table != NULL)
  114.         Free(tmp_table);
  115.  
  116.     for(i = 0; i < prog.total_dimensions; i++)
  117.     {
  118.         if (prog.trainset_sz && prog.train_table[i] != NULL)
  119.             Free(prog.train_table[i]);
  120.  
  121.         if (prog.testset_sz && prog.test_table[i] != NULL)
  122.             Free(prog.test_table[i]);
  123.     }
  124.  
  125.     if (prog.train_table != NULL)
  126.         Free(prog.train_table);
  127.  
  128.     if (prog.test_table != NULL)
  129.         Free(prog.test_table);
  130.  
  131.     if (prog.walk_step != NULL)
  132.         Free(prog.walk_step);
  133.  
  134.     if (prog.code != NULL)
  135.         Free(prog.code);
  136. }
  137.  
  138.  
  139. #ifndef YYLTYPE
  140. typedef
  141.   struct yyltype
  142.     {
  143.       int timestamp;
  144.       int first_line;
  145.       int first_column;
  146.       int last_line;
  147.       int last_column;
  148.       char *text;
  149.    }
  150.   yyltype;
  151.  
  152. #define YYLTYPE yyltype
  153. #endif
  154.  
  155. #ifndef YYSTYPE
  156. #define YYSTYPE int
  157. #endif
  158. #include <stdio.h>
  159.  
  160. #ifndef __STDC__
  161. #define const
  162. #endif
  163.  
  164.  
  165.  
  166. #define    YYFINAL        122
  167. #define    YYFLAG        -32768
  168. #define    YYNTBASE    32
  169.  
  170. #define YYTRANSLATE(x) ((unsigned)(x) <= 286 ? yytranslate[x] : 68)
  171.  
  172. static const char yytranslate[] = {     0,
  173.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  174.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  175.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  176.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  177.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  178.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  179.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  180.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  181.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  182.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  183.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  184.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  185.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  186.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  187.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  188.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  189.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  190.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  191.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  192.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  193.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  194.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  195.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  196.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  197.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  198.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  199.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  200.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  201.     26,    27,    28,    29,    30,    31
  202. };
  203.  
  204. #if YYDEBUG != 0
  205. static const short yyrline[] = { 0,
  206.    139,   140,   143,   178,   178,   190,   194,   207,   208,   211,
  207.    212,   213,   214,   215,   216,   217,   218,   219,   222,   235,
  208.    251,   265,   281,   294,   310,   337,   348,   352,   365,   372,
  209.    401,   421,   428,   457,   478,   491,   506,   507,   513,   519,
  210.    535,   543,   553,   559,   575,   583,   592,   594,   595,   597,
  211.    598,   599,   600,   601,   604,   627,   632,   637,   651,   657,
  212.    663
  213. };
  214.  
  215. static const char * const yytname[] = {     0,
  216. "error","$illegal.","FUNCTION","DOMAINS","CODOMAINS","DIMENSIONS","EQUALS","INTEGER","QUANTIZATION","COLON",
  217. "TRAINING","SET","_SIZE","TEST","CODING","LARGEST","SMALLEST","REAL","TREE","MIN",
  218. "MAX","CORRECT","EPOCHS","VOTE","IDENTIFIER","STRING","SAVE","TO","LOAD","FROM",
  219. "FOLDED","program"
  220. };
  221. #endif
  222.  
  223. static const short yyr1[] = {     0,
  224.     32,    32,    34,    33,    35,    36,    36,    37,    37,    38,
  225.     38,    38,    38,    38,    38,    38,    38,    38,    40,    39,
  226.     41,    41,    43,    42,    44,    44,    45,    45,    46,    48,
  227.     47,    49,    51,    50,    52,    52,    53,    53,    55,    54,
  228.     56,    56,    58,    57,    59,    59,    60,    61,    61,    62,
  229.     62,    62,    62,    62,    63,    64,    64,    64,    65,    66,
  230.     67
  231. };
  232.  
  233. static const short yyr2[] = {     0,
  234.      2,     2,     0,     5,     4,     0,     4,     1,     2,     1,
  235.      1,     1,     1,     1,     1,     1,     1,     1,     0,     4,
  236.      1,     2,     0,     4,     3,     4,     4,     4,     5,     0,
  237.      5,     5,     0,     5,     1,     2,     1,     1,     0,     4,
  238.      1,     2,     0,     4,     1,     2,     2,     1,     2,     1,
  239.      1,     1,     1,     1,     3,     4,     5,     4,     4,     4,
  240.      3
  241. };
  242.  
  243. static const short yydefact[] = {     0,
  244.      0,     0,     0,     0,     0,     6,     0,     0,     0,     0,
  245.      0,     0,    47,    48,    50,    51,    52,    53,    54,     1,
  246.      2,     0,     0,     3,     0,     0,     0,     0,     0,     0,
  247.      0,    49,     0,     0,     0,    55,     0,     0,    61,     0,
  248.      0,     0,     5,     0,     0,     0,     0,     0,     0,     0,
  249.      0,     0,     4,     8,    10,    11,    12,    13,    14,    15,
  250.     16,    17,    18,    59,    60,    56,     0,    58,     7,    19,
  251.      0,     0,    23,    39,    43,     0,     0,     9,    57,     0,
  252.     30,     0,    33,     0,     0,     0,     0,     0,     0,    21,
  253.     20,     0,     0,     0,     0,     0,    24,    38,    37,    41,
  254.     40,    45,    44,    27,    28,    22,    31,    35,    29,    34,
  255.     32,     0,     0,    42,    46,    36,    25,     0,    26,     0,
  256.      0,     0
  257. };
  258.  
  259. static const short yydefgoto[] = {   120,
  260.      3,    35,     6,    24,    53,    54,    55,    80,    91,    56,
  261.     85,    97,    57,    58,    59,    92,    60,    61,    94,   107,
  262.    108,    62,    86,   101,    63,    87,   103,     4,    13,    14,
  263.     15,    16,    17,    18,    19
  264. };
  265.  
  266. static const short yypact[] = {     0,
  267.      1,     5,    -6,     9,     8,    26,    21,    13,    14,    31,
  268.     -8,    22,     5,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  269. -32768,    32,    34,-32768,    35,    37,    38,    39,    18,    29,
  270.     12,-32768,    41,    43,    -7,-32768,    44,    45,-32768,    25,
  271.     27,    28,-32768,    48,    50,    46,    47,    53,    54,    55,
  272.     49,    51,    -7,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  273. -32768,-32768,-32768,-32768,-32768,-32768,    42,-32768,-32768,-32768,
  274.     20,    23,-32768,-32768,-32768,    52,    33,-32768,-32768,    57,
  275. -32768,    60,-32768,    62,    63,    -2,    -2,    56,    58,-32768,
  276.     64,    -2,    65,    -2,    66,    67,    68,-32768,-32768,-32768,
  277.     -2,-32768,    -2,-32768,-32768,-32768,    -2,-32768,-32768,    -2,
  278. -32768,    70,    69,-32768,-32768,-32768,-32768,    73,-32768,    75,
  279.     83,-32768
  280. };
  281.  
  282. static const short yypgoto[] = {-32768,
  283.     81,-32768,-32768,-32768,-32768,    17,-32768,-32768,-32768,-32768,
  284. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5,
  285.    -86,-32768,-32768,-32768,-32768,-32768,-32768,    84,-32768,    77,
  286. -32768,-32768,-32768,-32768,-32768
  287. };
  288.  
  289.  
  290. #define    YYLAST        90
  291.  
  292.  
  293. static const short yytable[] = {   100,
  294.    102,    45,     1,    46,     5,    98,    47,    48,    49,    50,
  295.     29,     1,     2,    22,   114,    99,   115,     7,     2,    51,
  296.    116,    52,    30,   116,     8,     9,    81,    25,    10,    83,
  297.     23,    11,    82,    12,    26,    84,    27,    28,    33,    34,
  298.     31,    42,    36,    37,    38,    40,    39,    41,    43,    44,
  299.     66,    64,    65,    68,    67,    69,    70,    71,    72,    73,
  300.     74,    75,    89,    76,    90,    77,    93,    79,    95,    78,
  301.     96,   106,   109,   111,   121,   113,   112,   117,   118,    88,
  302.    119,   104,   122,   105,    21,     0,    20,     0,   110,    32
  303. };
  304.  
  305. static const short yycheck[] = {    86,
  306.     87,     9,     3,    11,     4,     8,    14,    15,    16,    17,
  307.     19,     3,    19,     6,   101,    18,   103,    13,    19,    27,
  308.    107,    29,    31,   110,    20,    21,     7,     7,    24,     7,
  309.      5,    27,    13,    29,    22,    13,    23,     7,     7,     6,
  310.     19,    30,     8,     7,     7,    28,     8,    19,     8,     7,
  311.     26,     8,     8,    26,    28,     8,     7,    12,    12,     7,
  312.      7,     7,    30,    15,     8,    15,     7,    26,     7,    53,
  313.      8,     8,     8,     8,     0,     8,    10,     8,    10,    28,
  314.      8,    26,     0,    26,     4,    -1,     3,    -1,    94,    13
  315. };
  316. #define YYPURE 1
  317.  
  318. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  319. #line 3 "bison.sim"
  320.  
  321. /* modification made by MONROE THOMAS 07/18/91 after call to YYLEX to 
  322.    check for negative return value YYEXIT.  Needed for Windows version 
  323.    of parser where exit() calls are not desireable.  Instead, 
  324.    yyparse() will return YYABORT to its caller if yylex() returns 
  325.    YYEXIT.  Users should use return(1) calls in their action file that 
  326.    becomes part of yyparse() instead of exit(1) */
  327.  
  328. /* Skeleton output parser for bison,
  329.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  330.  
  331.    This program is free software; you can redistribute it and/or modify
  332.    it under the terms of the GNU General Public License as published by
  333.    the Free Software Foundation; either version 1, or (at your option)
  334.    any later version.
  335.  
  336.    This program is distributed in the hope that it will be useful,
  337.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  338.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  339.    GNU General Public License for more details.
  340.  
  341.    You should have received a copy of the GNU General Public License
  342.    along with this program; if not, write to the Free Software
  343.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  344.  
  345.  
  346. #ifdef __GNUC__
  347. #define alloca __builtin_alloca
  348. #else /* Not GNU C.  */
  349. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  350. #include <alloca.h>
  351. #endif /* Sparc.  */
  352. #endif /* Not GNU C.  */
  353.  
  354. /* This is the parser code that is written into each bison parser
  355.   when the %semantic_parser declaration is not specified in the grammar.
  356.   It was written by Richard Stallman by simplifying the hairy parser
  357.   used when %semantic_parser is specified.  */
  358.  
  359. /* Note: there must be only one dollar sign in this file.
  360.    It is replaced by the list of actions, each action
  361.    as one case of the switch.  */
  362.  
  363. #define yyerrok         (yyerrstatus = 0)
  364. #define yyclearin       (yychar = YYEMPTY)
  365. #define YYEMPTY         -2
  366.  
  367. /* next define added by M. THOMAS 07/18/91 */
  368.  
  369. #define YYEXIT          -3
  370.  
  371. #define YYEOF           0
  372. #define YYACCEPT        return(0)
  373. #define YYABORT         return(1)
  374. #define YYERROR         goto yyerrlab1
  375. /* Like YYERROR except do call yyerror.
  376.    This remains here temporarily to ease the
  377.    transition to the new meaning of YYERROR, for GCC.
  378.    Once GCC version 2 has supplanted version 1, this can go.  */
  379. #define YYFAIL          goto yyerrlab
  380. #define YYRECOVERING()  (!!yyerrstatus)
  381. #define YYBACKUP(token, value) \
  382. do                                                              \
  383.   if (yychar == YYEMPTY && yylen == 1)                          \
  384.     { yychar = (token), yylval = (value);                       \
  385.       yychar1 = YYTRANSLATE (yychar);                           \
  386.       YYPOPSTACK;                                               \
  387.       goto yybackup;                                            \
  388.     }                                                           \
  389.   else                                                          \
  390.     { yyerror ("syntax error: cannot back up"); YYERROR; }      \
  391. while (0)
  392.  
  393. #define YYTERROR        1
  394. #define YYERRCODE       256
  395.  
  396. #ifndef YYIMPURE
  397. #define YYLEX           yylex()
  398. #endif
  399.  
  400. #ifndef YYPURE
  401. #define YYLEX           yylex(&yylval, &yylloc)
  402. #endif
  403.  
  404. /* If nonreentrant, generate the variables here */
  405.  
  406. #ifndef YYIMPURE
  407.  
  408. int     yychar;                 /*  the lookahead symbol                */
  409. YYSTYPE yylval;                 /*  the semantic value of the           */
  410.                 /*  lookahead symbol                    */
  411.  
  412. #ifdef YYLSP_NEEDED
  413. YYLTYPE yylloc;                 /*  location data for the lookahead     */
  414.                 /*  symbol                              */
  415. #endif
  416.  
  417. int yynerrs;                    /*  number of parse errors so far       */
  418. #endif  /* YYIMPURE */
  419.  
  420. #if YYDEBUG != 0
  421. int yydebug;                    /*  nonzero means print parse trace     */
  422. /* Since this is uninitialized, it does not stop multiple parsers
  423.    from coexisting.  */
  424. #endif
  425.  
  426. /*  YYINITDEPTH indicates the initial size of the parser's stacks       */
  427.  
  428. #ifndef YYINITDEPTH
  429. #define YYINITDEPTH 200
  430. #endif
  431.  
  432. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  433.     (effective only if the built-in stack extension method is used).  */
  434.  
  435. #if YYMAXDEPTH == 0
  436. #undef YYMAXDEPTH
  437. #endif
  438.  
  439. #ifndef YYMAXDEPTH
  440. #define YYMAXDEPTH 10000
  441. #endif
  442.  
  443. /* This is the most reliable way to avoid incompatibilities
  444.    in available built-in functions on various systems.  */
  445. static void
  446. __yy_bcopy (from, to, count)
  447.      char *from;
  448.      char *to;
  449.      int count;
  450. {
  451.   register char *f = from;
  452.   register char *t = to;
  453.   register int i = count;
  454.  
  455.   while (i-- > 0)
  456.     *t++ = *f++;
  457. }
  458.  
  459. #line 143 "bison.sim"
  460. int
  461. yyparse()
  462. {
  463.   register int yystate;
  464.   register int yyn;
  465.   register short *yyssp;
  466.   register YYSTYPE *yyvsp;
  467.   int yyerrstatus;      /*  number of tokens to shift before error messages enabled */
  468.   int yychar1;          /*  lookahead token as an internal (translated) token number */
  469.  
  470.   short yyssa[YYINITDEPTH];     /*  the state stack                     */
  471.   YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
  472.  
  473.   short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
  474.   YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
  475.  
  476. #ifdef YYLSP_NEEDED
  477.   YYLTYPE *yyls = yylsa;
  478.   YYLTYPE *yylsp;
  479.   YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
  480.  
  481. #define YYPOPSTACK   (yyvsp--, yysp--, yylsp--)
  482. #else
  483. #define YYPOPSTACK   (yyvsp--, yysp--)
  484. #endif
  485.  
  486.   int yystacksize = YYINITDEPTH;
  487.  
  488. #ifndef YYPURE
  489.   int yychar;
  490.   YYSTYPE yylval;
  491.   int yynerrs;
  492. #ifdef YYLSP_NEEDED
  493.   YYLTYPE yylloc;
  494. #endif
  495. #endif
  496.  
  497.   YYSTYPE yyval;                /*  the variable used to return         */
  498.                 /*  semantic values from the action     */
  499.                 /*  routines                            */
  500.  
  501.   int yylen;
  502.  
  503. #if YYDEBUG != 0
  504.   if (yydebug)
  505.     fprintf(stderr, "Starting parse\n");
  506. #endif
  507.  
  508.   yystate = 0;
  509.   yyerrstatus = 0;
  510.   yynerrs = 0;
  511.   yychar = YYEMPTY;             /* Cause a token to be read.  */
  512.  
  513.   /* Initialize stack pointers.
  514.      Waste one element of value and location stack
  515.      so that they stay on the same level as the state stack.  */
  516.  
  517.   yyssp = yyss - 1;
  518.   yyvsp = yyvs;
  519. #ifdef YYLSP_NEEDED
  520.   yylsp = yyls;
  521. #endif
  522.  
  523. /* Push a new state, which is found in  yystate  .  */
  524. /* In all cases, when you get here, the value and location stacks
  525.    have just been pushed. so pushing a state here evens the stacks.  */
  526. yynewstate:
  527.  
  528.   *++yyssp = yystate;
  529.  
  530.   if (yyssp >= yyss + yystacksize - 1)
  531.     {
  532.       /* Give user a chance to reallocate the stack */
  533.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  534.       YYSTYPE *yyvs1 = yyvs;
  535.       short *yyss1 = yyss;
  536. #ifdef YYLSP_NEEDED
  537.       YYLTYPE *yyls1 = yyls;
  538. #endif
  539.  
  540.       /* Get the current used size of the three stacks, in elements.  */
  541.       int size = yyssp - yyss + 1;
  542.  
  543. #ifdef yyoverflow
  544.       /* Each stack pointer address is followed by the size of
  545.      the data in use in that stack, in bytes.  */
  546.       yyoverflow("parser stack overflow",
  547.          &yyss1, size * sizeof (*yyssp),
  548.          &yyvs1, size * sizeof (*yyvsp),
  549. #ifdef YYLSP_NEEDED
  550.          &yyls1, size * sizeof (*yylsp),
  551. #endif
  552.          &yystacksize);
  553.  
  554.       yyss = yyss1; yyvs = yyvs1;
  555. #ifdef YYLSP_NEEDED
  556.       yyls = yyls1;
  557. #endif
  558. #else /* no yyoverflow */
  559.       /* Extend the stack our own way.  */
  560.       if (yystacksize >= YYMAXDEPTH)
  561.     {
  562.       yyerror("parser stack overflow");
  563.       return 2;
  564.     }
  565.       yystacksize *= 2;
  566.       if (yystacksize > YYMAXDEPTH)
  567.     yystacksize = YYMAXDEPTH;
  568.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  569.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  570.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  571.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  572. #ifdef YYLSP_NEEDED
  573.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  574.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  575. #endif
  576. #endif /* no yyoverflow */
  577.  
  578.       yyssp = yyss + size - 1;
  579.       yyvsp = yyvs + size - 1;
  580. #ifdef YYLSP_NEEDED
  581.       yylsp = yyls + size - 1;
  582. #endif
  583.  
  584. #if YYDEBUG != 0
  585.       if (yydebug)
  586.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  587. #endif
  588.  
  589.       if (yyssp >= yyss + yystacksize - 1)
  590.     YYABORT;
  591.     }
  592.  
  593. #if YYDEBUG != 0
  594.   if (yydebug)
  595.     fprintf(stderr, "Entering state %d\n", yystate);
  596. #endif
  597.  
  598.  yybackup:
  599.  
  600. /* Do appropriate processing given the current state.  */
  601. /* Read a lookahead token if we need one and don't already have one.  */
  602. /* yyresume: */
  603.  
  604.   /* First try to decide what to do without reference to lookahead token.  */
  605.  
  606.   yyn = yypact[yystate];
  607.   if (yyn == YYFLAG)
  608.     goto yydefault;
  609.  
  610.   /* Not known => get a lookahead token if don't already have one.  */
  611.  
  612.   /* yychar is either YYEMPTY or YYEOF
  613.      or a valid token in external form.  */
  614.  
  615.   if (yychar == YYEMPTY)
  616.     {
  617. #if YYDEBUG != 0
  618.       if (yydebug)
  619.     fprintf(stderr, "Reading a token: ");
  620. #endif
  621.       yychar = YYLEX;
  622.  
  623.   /* next test added by M. THOMAS. 07/18/91 */
  624.  
  625.       if (yychar == YYEXIT) YYABORT;
  626.     }
  627.  
  628.   /* Convert token to internal form (in yychar1) for indexing tables with */
  629.  
  630.   if (yychar <= 0)              /* This means end of input. */
  631.     {
  632.       yychar1 = 0;
  633.       yychar = YYEOF;           /* Don't call YYLEX any more */
  634.  
  635. #if YYDEBUG != 0
  636.       if (yydebug)
  637.     fprintf(stderr, "Now at end of input.\n");
  638. #endif
  639.     }
  640.   else
  641.     {
  642.       yychar1 = YYTRANSLATE(yychar);
  643.  
  644. #if YYDEBUG != 0
  645.       if (yydebug)
  646.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  647. #endif
  648.     }
  649.  
  650.   yyn += yychar1;
  651.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  652.     goto yydefault;
  653.  
  654.   yyn = yytable[yyn];
  655.  
  656.   /* yyn is what to do for this token type in this state.
  657.      Negative => reduce, -yyn is rule number.
  658.      Positive => shift, yyn is new state.
  659.        New state is final state => don't bother to shift,
  660.        just return success.
  661.      0, or most negative number => error.  */
  662.  
  663.   if (yyn < 0)
  664.     {
  665.       if (yyn == YYFLAG)
  666.     goto yyerrlab;
  667.       yyn = -yyn;
  668.       goto yyreduce;
  669.     }
  670.   else if (yyn == 0)
  671.     goto yyerrlab;
  672.  
  673.   if (yyn == YYFINAL)
  674.     YYACCEPT;
  675.  
  676.   /* Shift the lookahead token.  */
  677.  
  678. #if YYDEBUG != 0
  679.   if (yydebug)
  680.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  681. #endif
  682.  
  683.   /* Discard the token being shifted unless it is eof.  */
  684.   if (yychar != YYEOF)
  685.     yychar = YYEMPTY;
  686.  
  687.   *++yyvsp = yylval;
  688. #ifdef YYLSP_NEEDED
  689.   *++yylsp = yylloc;
  690. #endif
  691.  
  692.   /* count tokens shifted since error; after three, turn off error status.  */
  693.   if (yyerrstatus) yyerrstatus--;
  694.  
  695.   yystate = yyn;
  696.   goto yynewstate;
  697.  
  698. /* Do the default action for the current state.  */
  699. yydefault:
  700.  
  701.   yyn = yydefact[yystate];
  702.   if (yyn == 0)
  703.     goto yyerrlab;
  704.  
  705. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  706. yyreduce:
  707.   yylen = yyr2[yyn];
  708.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  709.  
  710. #if YYDEBUG != 0
  711.   if (yydebug)
  712.     {
  713.       if (yylen == 1)
  714.     fprintf (stderr, "Reducing 1 value via rule %d (line %d), ",
  715.          yyn, yyrline[yyn]);
  716.       else
  717.     fprintf (stderr, "Reducing %d values via rule %d (line %d), ",
  718.          yylen, yyn, yyrline[yyn]);
  719.     }
  720. #endif
  721.  
  722.  
  723.   switch (yyn) {
  724.  
  725. case 3:
  726. #line 144 "winsynan.y"
  727. {
  728.                   int dim;
  729.  
  730.                   prog.total_dimensions = prog.dimensions + prog.codimensions;
  731.  
  732.                   prog.train_table = (float far * far *)
  733.                       Malloc((unsigned)sizeof(float far *) * prog.total_dimensions);
  734.                   MEMCHECK(prog.train_table);
  735.  
  736.                   prog.test_table = (float far * far *)
  737.                       Malloc((unsigned)sizeof(float far *) * prog.total_dimensions);
  738.                   MEMCHECK(prog.test_table);
  739.  
  740.                   prog.walk_step = (int far *)
  741.                       Malloc((unsigned)sizeof(int) * prog.total_dimensions);
  742.                   MEMCHECK(prog.walk_step);
  743.  
  744.                   prog.code = (LPCODE_T)
  745.                       Malloc((unsigned)sizeof(code_t) * prog.total_dimensions);
  746.                   MEMCHECK(prog.code);
  747.  
  748.                   tmp_table = (float far * far *)
  749.                       Malloc((unsigned)sizeof(float far *) * prog.total_dimensions);
  750.                   MEMCHECK(tmp_table);
  751.  
  752.                   for(dim = 0; dim < prog.total_dimensions; dim++)
  753.                   {
  754.                       prog.test_table[dim] = NULL;
  755.                       prog.train_table[dim] = NULL;
  756.                       tmp_table[dim] = NULL;
  757.                   }
  758.              ;
  759.     break;}
  760. case 5:
  761. #line 179 "winsynan.y"
  762. {
  763.               prog.dimensions = yyvsp[0].i;
  764.               if (prog.dimensions < 1)
  765.               {
  766.                   wsprintf(szBuffer, "number of domain dimensions must be at least 1, line %d.\n", line_no);
  767.                   MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  768.                   yyerrexit();
  769.                   return(1);
  770.               }
  771.           ;
  772.     break;}
  773. case 6:
  774. #line 191 "winsynan.y"
  775. {
  776.                 prog.codimensions = 1;
  777.             ;
  778.     break;}
  779. case 7:
  780. #line 195 "winsynan.y"
  781. {
  782.                 prog.codimensions = yyvsp[0].i;
  783.                 if (prog.codimensions < 1)
  784.                 {
  785.                     wsprintf(szBuffer, "number of codomain dimensions must be at least 1, line %d.\n", line_no);
  786.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  787.                     yyerrexit();
  788.                     return(1);
  789.                 }
  790.             ;
  791.     break;}
  792. case 19:
  793. #line 223 "winsynan.y"
  794. {
  795.                  tuple_ptr = 0;
  796.                  quant_flag = TRUE;
  797.                  if (prog.load_code)
  798.                  {
  799.                      wsprintf(szBuffer,
  800.                         "warning: coding(s) will be read from file '%s',\n\tquantization statement ignored, line %d.\n",
  801.                         (LPSTR)prog.load_code,line_no);
  802.                      MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  803.                  }
  804.              ;
  805.     break;}
  806. case 20:
  807. #line 235 "winsynan.y"
  808. {
  809.                  if (tuple_ptr > prog.total_dimensions)
  810.                  {
  811.                      prog.error = TRUE;
  812.                      wsprintf(szBuffer, "too many elements in quantization list on line %d.\n", line_no);
  813.                      MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  814.                  }
  815.                  if (tuple_ptr < prog.total_dimensions)
  816.                  {
  817.                      prog.error = TRUE;
  818.                      wsprintf(szBuffer, "too few elements in quantization list on line %d.\n", line_no);
  819.                      MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  820.                  }
  821.             ;
  822.     break;}
  823. case 21:
  824. #line 252 "winsynan.y"
  825. {
  826.                if (tuple_ptr < prog.total_dimensions)
  827.                {
  828.                    prog.code[tuple_ptr].vector_count = yyvsp[0].i;
  829.                    if (yyvsp[0].i < 2)
  830.                    {
  831.                        prog.error = TRUE;
  832.                        wsprintf(szBuffer, "must have at least 2 quantization levels, column %d.\n", tuple_ptr + 1);
  833.                        MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  834.                    }
  835.                }
  836.                tuple_ptr++;
  837.            ;
  838.     break;}
  839. case 22:
  840. #line 266 "winsynan.y"
  841. {
  842.                if (tuple_ptr < prog.total_dimensions)
  843.                {
  844.                    prog.code[tuple_ptr].vector_count = yyvsp[0].i;
  845.                    if (yyvsp[0].i < 2)
  846.                    {
  847.                        prog.error = TRUE;
  848.                        wsprintf(szBuffer, "must have at least 2 quantization levels, column %d.\n", tuple_ptr + 1);
  849.                        MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  850.                    }
  851.                }
  852.                tuple_ptr++;
  853.            ;
  854.     break;}
  855. case 23:
  856. #line 282 "winsynan.y"
  857. {
  858.            tuple_ptr = 0;
  859.            code_flag = TRUE;
  860.            if (prog.load_code)
  861.            {
  862.                wsprintf(szBuffer,
  863.                     "warning: coding(s) will be read from file '%s',\n\tcoding statement ignored, line %d.\n",
  864.                          (LPSTR)prog.load_code, line_no);
  865.                MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  866.            }
  867.        ;
  868.     break;}
  869. case 24:
  870. #line 294 "winsynan.y"
  871. {
  872.            if (tuple_ptr > prog.total_dimensions)
  873.            {
  874.                prog.error = TRUE;
  875.                wsprintf(szBuffer, "too many elements in coding list on line %d.\n", line_no);
  876.                MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  877.            }
  878.            if (tuple_ptr < prog.total_dimensions)
  879.            {
  880.                prog.error = TRUE;
  881.                wsprintf(szBuffer, "too few elements in coding list on line %d.\n", line_no);
  882.                MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  883.            }
  884.        ;
  885.     break;}
  886. case 25:
  887. #line 311 "winsynan.y"
  888. {
  889.               if (tuple_ptr < prog.total_dimensions)
  890.               {
  891.                   prog.code[tuple_ptr].width = yyvsp[-2].i;
  892.                   prog.walk_step[tuple_ptr] = yyvsp[0].i;
  893.                   if (yyvsp[-2].i < 1)
  894.                   {
  895.                       prog.error = TRUE;
  896.                       wsprintf(szBuffer, "coding width must be at least 1, column %d.\n", tuple_ptr + 1);
  897.                       MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  898.                   }
  899.                   if (yyvsp[0].i < 1)
  900.                   {
  901.                       prog.error = TRUE;
  902.                       wsprintf(szBuffer, "coding distance must be at least 1, column %d.\n", tuple_ptr + 1);
  903.                       MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  904.                   }
  905.                   if (yyvsp[0].i > yyvsp[-2].i)
  906.                   {
  907.                       prog.error = TRUE;
  908.                       wsprintf(szBuffer, "coding distance must not be greater than coding width, column %d.\n", tuple_ptr + 1);
  909.                       MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  910.                   }
  911.               }
  912.               tuple_ptr++;
  913.           ;
  914.     break;}
  915. case 26:
  916. #line 338 "winsynan.y"
  917. {
  918.               if (tuple_ptr < prog.total_dimensions)
  919.               {
  920.                   prog.code[tuple_ptr].width = yyvsp[-2].i;
  921.                   prog.walk_step[tuple_ptr] = yyvsp[0].i;
  922.               }
  923.               tuple_ptr++;
  924.           ;
  925.     break;}
  926. case 27:
  927. #line 349 "winsynan.y"
  928. {
  929.               prog.save_code = yyvsp[0].s;
  930.           ;
  931.     break;}
  932. case 28:
  933. #line 353 "winsynan.y"
  934. {
  935.               prog.load_code = yyvsp[0].s;
  936.               if (code_flag || quant_flag)
  937.               {
  938.                   wsprintf(szBuffer,
  939.                         "warning: coding(s) will be read from file '%s',\n\tcoding and quantization statements ignored.\n",
  940.                          (LPSTR)prog.load_code);
  941.                   MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  942.               }
  943.           ;
  944.     break;}
  945. case 29:
  946. #line 366 "winsynan.y"
  947. {
  948.                 prog.trainset_sz = yyvsp[0].i;
  949.                 train_size_flag = TRUE;
  950.             ;
  951.     break;}
  952. case 30:
  953. #line 373 "winsynan.y"
  954. {
  955.                 if (!train_size_flag)
  956.                 {
  957.                     wsprintf(szBuffer, "training set defined before size.\n");
  958.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  959.                     yyerrexit();
  960.                     return(1);
  961.                 }
  962.                 else
  963.                 {
  964.                     int dim;
  965.  
  966.                     tuple_ptr = 0;
  967.                     table_ptr = 0;
  968.                     table_size = prog.trainset_sz;
  969.  
  970.                     if (table_size > 0)
  971.                     {
  972.                         for (dim = 0; dim < prog.total_dimensions; dim++)
  973.                         {
  974.                             tmp_table[dim] = (float far *)
  975.                                 Malloc((unsigned) sizeof(float) * table_size);
  976.                             MEMCHECK(tmp_table[dim]);
  977.                         }
  978.                     }
  979.                 }
  980.             ;
  981.     break;}
  982. case 31:
  983. #line 401 "winsynan.y"
  984. {
  985.                 int dim;
  986.  
  987.                 if (tuple_ptr < prog.trainset_sz)
  988.                 {
  989.                     prog.error = TRUE;
  990.                     wsprintf(szBuffer,"too few elements in training set.\n");
  991.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  992.                 }
  993.                 else if (tuple_ptr > prog.trainset_sz || table_ptr != 0)
  994.                 {
  995.                     wsprintf(szBuffer, "warning: extra elements in training set ignored.\n");
  996.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  997.                 }
  998.                 for (dim = 0; dim < prog.total_dimensions; dim++)
  999.                 {
  1000.                     prog.train_table[dim] = (prog.trainset_sz ? tmp_table[dim] : NULL);
  1001.                 }
  1002.             ;
  1003.     break;}
  1004. case 32:
  1005. #line 422 "winsynan.y"
  1006. {
  1007.                 prog.testset_sz = yyvsp[0].i;
  1008.                 test_size_flag = TRUE;
  1009.             ;
  1010.     break;}
  1011. case 33:
  1012. #line 429 "winsynan.y"
  1013. {
  1014.                 if (!test_size_flag)
  1015.                 {
  1016.                     wsprintf(szBuffer, "test set defined before size.\n");
  1017.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1018.                     yyerrexit();
  1019.                     return(1);
  1020.                 }
  1021.                 else
  1022.                 {
  1023.                     int dim;
  1024.  
  1025.                     tuple_ptr = 0;
  1026.                     table_ptr = 0;
  1027.                     table_size = prog.testset_sz;
  1028.  
  1029.                     if (table_size > 0)
  1030.                     {
  1031.                         for (dim = 0; dim < prog.total_dimensions; dim++)
  1032.                         {
  1033.                             tmp_table[dim] = (float far *)
  1034.                                 Malloc((unsigned)sizeof(float) * table_size);
  1035.                             MEMCHECK(tmp_table[dim]);
  1036.                         }
  1037.                     }
  1038.                 }
  1039.             ;
  1040.     break;}
  1041. case 34:
  1042. #line 457 "winsynan.y"
  1043. {
  1044.                 int dim;
  1045.  
  1046.                 if (tuple_ptr < prog.testset_sz)
  1047.                 {
  1048.                     prog.error = TRUE;
  1049.                     wsprintf(szBuffer, "too few elements in test set.\n");
  1050.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1051.                 }
  1052.                 else if (tuple_ptr > prog.testset_sz || table_ptr != 0)
  1053.                 {
  1054.                     wsprintf(szBuffer, "warning: extra elements in test set ignored.\n");
  1055.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1056.                 }
  1057.                 for (dim = 0; dim < prog.total_dimensions; dim++)
  1058.                 {
  1059.                     prog.test_table[dim] = (prog.testset_sz ? tmp_table[dim] : NULL);
  1060.                 }
  1061.             ;
  1062.     break;}
  1063. case 35:
  1064. #line 479 "winsynan.y"
  1065. {
  1066.           if (tuple_ptr < table_size)
  1067.           {
  1068.               tmp_table[table_ptr][tuple_ptr] = yyvsp[0].f;
  1069.           }
  1070.           table_ptr++;
  1071.           if (table_ptr == prog.total_dimensions)
  1072.           {
  1073.               table_ptr = 0;
  1074.               tuple_ptr++;
  1075.           }
  1076.       ;
  1077.     break;}
  1078. case 36:
  1079. #line 492 "winsynan.y"
  1080. {
  1081.           if (tuple_ptr < table_size)
  1082.           {
  1083.               tmp_table[table_ptr][tuple_ptr] = yyvsp[0].f;
  1084.           }
  1085.           table_ptr++;
  1086.           if (table_ptr == prog.total_dimensions)
  1087.           {
  1088.               table_ptr = 0;
  1089.               tuple_ptr++;
  1090.           }
  1091.       ;
  1092.     break;}
  1093. case 38:
  1094. #line 508 "winsynan.y"
  1095. {
  1096.         yyval.f = (float) yyvsp[0].i;
  1097.     ;
  1098.     break;}
  1099. case 39:
  1100. #line 514 "winsynan.y"
  1101. {
  1102.                  tuple_ptr = 0;
  1103.                  largest_flag = TRUE;
  1104.              ;
  1105.     break;}
  1106. case 40:
  1107. #line 519 "winsynan.y"
  1108. {
  1109.                  if (tuple_ptr > prog.total_dimensions)
  1110.                  {
  1111.                      prog.error = TRUE;
  1112.                      wsprintf(szBuffer, "too many elements in largest list on line %d.\n", line_no);
  1113.                      MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1114.                  }
  1115.                  if (tuple_ptr < prog.total_dimensions)
  1116.                  {
  1117.                      prog.error = TRUE;
  1118.                      wsprintf(szBuffer, "too few elements in largest list on line %d.\n", line_no);
  1119.                      MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1120.                  }
  1121.              ;
  1122.     break;}
  1123. case 41:
  1124. #line 536 "winsynan.y"
  1125. {
  1126.                  if (tuple_ptr < prog.total_dimensions)
  1127.                  {
  1128.                      prog.code[tuple_ptr].high = yyvsp[0].f;
  1129.                  }
  1130.                  tuple_ptr++;
  1131.              ;
  1132.     break;}
  1133. case 42:
  1134. #line 544 "winsynan.y"
  1135. {
  1136.                  if (tuple_ptr < prog.total_dimensions)
  1137.                  {
  1138.                      prog.code[tuple_ptr].high = yyvsp[0].f;
  1139.                  }
  1140.                  tuple_ptr++;
  1141.              ;
  1142.     break;}
  1143. case 43:
  1144. #line 554 "winsynan.y"
  1145. {
  1146.                  tuple_ptr = 0;
  1147.                  smallest_flag = TRUE;
  1148.              ;
  1149.     break;}
  1150. case 44:
  1151. #line 559 "winsynan.y"
  1152. {
  1153.                  if (tuple_ptr > prog.total_dimensions)
  1154.                  {
  1155.                      prog.error = TRUE;
  1156.                      wsprintf(szBuffer, "too many elements in smallest list on line %d.\n", line_no);
  1157.                      MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1158.                  }
  1159.                  else if (tuple_ptr < prog.total_dimensions)
  1160.                  {
  1161.                      prog.error = TRUE;
  1162.                      wsprintf(szBuffer, "too few elements in smallest list on line %d.\n", line_no);
  1163.                      MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1164.                  }
  1165.              ;
  1166.     break;}
  1167. case 45:
  1168. #line 576 "winsynan.y"
  1169. {
  1170.                  if (tuple_ptr < prog.total_dimensions)
  1171.                  {
  1172.                      prog.code[tuple_ptr].low = yyvsp[0].f;
  1173.                  }
  1174.                  tuple_ptr++;
  1175.              ;
  1176.     break;}
  1177. case 46:
  1178. #line 584 "winsynan.y"
  1179. {
  1180.                  if (tuple_ptr < prog.total_dimensions)
  1181.                  {
  1182.                      prog.code[tuple_ptr].low = yyvsp[0].f;
  1183.                  }
  1184.                  tuple_ptr++;
  1185.              ;
  1186.     break;}
  1187. case 55:
  1188. #line 605 "winsynan.y"
  1189. {
  1190.               if (prog.load_tree)
  1191.               {
  1192.                   wsprintf(szBuffer,
  1193.                           "warning: tree(s) will be read from file '%s',\n\ttree size statement ignored, line %d.\n",
  1194.                            (LPSTR)prog.load_tree, line_no);
  1195.                   MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1196.               }
  1197.               else if (yyvsp[0].i < 1)
  1198.               {
  1199.                   wsprintf(szBuffer, "lf: tree size too small, line %d.\n",
  1200.                                  line_no);
  1201.                   MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1202.                   prog.error++;
  1203.               }
  1204.               else
  1205.               {
  1206.                   prog.tree_sz = yyvsp[0].i;
  1207.               }
  1208.           ;
  1209.     break;}
  1210. case 56:
  1211. #line 628 "winsynan.y"
  1212. {
  1213.             prog.save_tree = yyvsp[0].s;
  1214.             fold_flag = FALSE;
  1215.         ;
  1216.     break;}
  1217. case 57:
  1218. #line 633 "winsynan.y"
  1219. {
  1220.             prog.save_tree = yyvsp[0].s;
  1221.             fold_flag = TRUE;
  1222.         ;
  1223.     break;}
  1224. case 58:
  1225. #line 638 "winsynan.y"
  1226. {
  1227.             prog.load_tree = yyvsp[0].s;
  1228.             if (prog.tree_sz > 0)
  1229.             {
  1230.                 wsprintf(szBuffer,
  1231.                           "lf: warning: tree(s) will be read from file '%s',\n\ttree size statement ignored, line %d.\n",
  1232.                           (LPSTR)prog.load_tree,line_no);
  1233.                 MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1234.             }
  1235.         ;
  1236.     break;}
  1237. case 59:
  1238. #line 652 "winsynan.y"
  1239. {
  1240.                 prog.min_correct = yyvsp[0].i;
  1241.             ;
  1242.     break;}
  1243. case 60:
  1244. #line 658 "winsynan.y"
  1245. {
  1246.                prog.max_epochs = yyvsp[0].i;
  1247.            ;
  1248.     break;}
  1249. case 61:
  1250. #line 664 "winsynan.y"
  1251. {
  1252.             if (yyvsp[0].i % 2 != 1)
  1253.             {
  1254.                 wsprintf(szBuffer,
  1255.                                "vote number must be odd, line %d.\n",
  1256.                                line_no);
  1257.                 MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1258.                 yyerrexit();
  1259.                 return(1);
  1260.             }
  1261.             prog.vote = yyvsp[0].i;
  1262.         ;
  1263.     break;}
  1264. }
  1265.    /* the action file gets copied in in place of this dollarsign */
  1266. #line 378 "bison.sim"
  1267.  
  1268.   yyvsp -= yylen;
  1269.   yyssp -= yylen;
  1270. #ifdef YYLSP_NEEDED
  1271.   yylsp -= yylen;
  1272. #endif
  1273.  
  1274. #if YYDEBUG != 0
  1275.   if (yydebug)
  1276.     {
  1277.       short *ssp1 = yyss - 1;
  1278.       fprintf (stderr, "state stack now");
  1279.       while (ssp1 != yyssp)
  1280.     fprintf (stderr, " %d", *++ssp1);
  1281.       fprintf (stderr, "\n");
  1282.     }
  1283. #endif
  1284.  
  1285.   *++yyvsp = yyval;
  1286.  
  1287. #ifdef YYLSP_NEEDED
  1288.   yylsp++;
  1289.   if (yylen == 0)
  1290.     {
  1291.       yylsp->first_line = yylloc.first_line;
  1292.       yylsp->first_column = yylloc.first_column;
  1293.       yylsp->last_line = (yylsp-1)->last_line;
  1294.       yylsp->last_column = (yylsp-1)->last_column;
  1295.       yylsp->text = 0;
  1296.     }
  1297.   else
  1298.     {
  1299.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1300.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1301.     }
  1302. #endif
  1303.  
  1304.   /* Now "shift" the result of the reduction.
  1305.      Determine what state that goes to,
  1306.      based on the state we popped back to
  1307.      and the rule number reduced by.  */
  1308.  
  1309.   yyn = yyr1[yyn];
  1310.  
  1311.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1312.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1313.     yystate = yytable[yystate];
  1314.   else
  1315.     yystate = yydefgoto[yyn - YYNTBASE];
  1316.  
  1317.   goto yynewstate;
  1318.  
  1319. yyerrlab:   /* here on detecting error */
  1320.  
  1321.   if (! yyerrstatus)
  1322.     /* If not already recovering from an error, report this error.  */
  1323.     {
  1324.       ++yynerrs;
  1325.  
  1326. #ifdef YYERROR_VERBOSE
  1327.       yyn = yypact[yystate];
  1328.  
  1329.       if (yyn > YYFLAG && yyn < YYLAST)
  1330.     {
  1331.       int size = 0;
  1332.       char *msg;
  1333.       int x, count;
  1334.  
  1335.       count = 0;
  1336.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1337.         if (yycheck[x + yyn] == x)
  1338.           size += strlen(yytname[x]) + 15, count++;
  1339.       msg = (char *) xmalloc(size + 15);
  1340.       strcpy(msg, "parse error");
  1341.  
  1342.       if (count < 5)
  1343.         {
  1344.           count = 0;
  1345.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1346.         if (yycheck[x + yyn] == x)
  1347.           {
  1348.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1349.             strcat(msg, yytname[x]);
  1350.             strcat(msg, "'");
  1351.             count++;
  1352.           }
  1353.         }
  1354.       yyerror(msg);
  1355.       free(msg);
  1356.     }
  1357.       else
  1358. #endif /* YYERROR_VERBOSE */
  1359.     yyerror("parse error");
  1360.     }
  1361.  
  1362. yyerrlab1:   /* here on error raised explicitly by an action */
  1363.  
  1364.   if (yyerrstatus == 3)
  1365.     {
  1366.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1367.  
  1368.       /* return failure if at end of input */
  1369.       if (yychar == YYEOF)
  1370.     YYABORT;
  1371.  
  1372. #if YYDEBUG != 0
  1373.       if (yydebug)
  1374.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1375. #endif
  1376.  
  1377.       yychar = YYEMPTY;
  1378.     }
  1379.  
  1380.   /* Else will try to reuse lookahead token
  1381.      after shifting the error token.  */
  1382.  
  1383.   yyerrstatus = 3;              /* Each real token shifted decrements this */
  1384.  
  1385.   goto yyerrhandle;
  1386.  
  1387. yyerrdefault:  /* current state does not do anything special for the error token. */
  1388.  
  1389. #if 0
  1390.   /* This is wrong; only states that explicitly want error tokens
  1391.      should shift them.  */
  1392.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1393.   if (yyn) goto yydefault;
  1394. #endif
  1395.  
  1396. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1397.  
  1398.   if (yyssp == yyss) YYABORT;
  1399.   yyvsp--;
  1400.   yystate = *--yyssp;
  1401. #ifdef YYLSP_NEEDED
  1402.   yylsp--;
  1403. #endif
  1404.  
  1405. #if YYDEBUG != 0
  1406.   if (yydebug)
  1407.     {
  1408.       short *ssp1 = yyss - 1;
  1409.       fprintf (stderr, "Error: state stack now");
  1410.       while (ssp1 != yyssp)
  1411.     fprintf (stderr, " %d", *++ssp1);
  1412.       fprintf (stderr, "\n");
  1413.     }
  1414. #endif
  1415.  
  1416. yyerrhandle:
  1417.  
  1418.   yyn = yypact[yystate];
  1419.   if (yyn == YYFLAG)
  1420.     goto yyerrdefault;
  1421.  
  1422.   yyn += YYTERROR;
  1423.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1424.     goto yyerrdefault;
  1425.  
  1426.   yyn = yytable[yyn];
  1427.   if (yyn < 0)
  1428.     {
  1429.       if (yyn == YYFLAG)
  1430.     goto yyerrpop;
  1431.       yyn = -yyn;
  1432.       goto yyreduce;
  1433.     }
  1434.   else if (yyn == 0)
  1435.     goto yyerrpop;
  1436.  
  1437.   if (yyn == YYFINAL)
  1438.     YYACCEPT;
  1439.  
  1440. #if YYDEBUG != 0
  1441.   if (yydebug)
  1442.     fprintf(stderr, "Shifting error token, ");
  1443. #endif
  1444.  
  1445.   *++yyvsp = yylval;
  1446. #ifdef YYLSP_NEEDED
  1447.   *++yylsp = yylloc;
  1448. #endif
  1449.  
  1450.   yystate = yyn;
  1451.   goto yynewstate;
  1452. }
  1453. #line 677 "winsynan.y"
  1454.  
  1455.  
  1456. yyerror(description)
  1457. char *description;
  1458. {
  1459.     wsprintf(szBuffer, "%s, line %d.\n", (LPSTR)description, line_no);
  1460.     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1461.     prog.error = TRUE;
  1462.     yyerrexit();    /* prepare for exit */
  1463.     return(0);
  1464. }
  1465.  
  1466.  
  1467. /* Lexical states */
  1468.  
  1469. #define LEX_START 0
  1470. #define LEX_INT 1
  1471. #define LEX_DEC 2
  1472. #define LEX_IDENT 3
  1473. #define LEX_PUNCT 4
  1474. #define LEX_COMMENT 5
  1475. #define LEX_STRING 6
  1476. #define LEX_STOP 1000
  1477.  
  1478. #define ISCOMMENT(c) ((c) == '#')
  1479. #define MAX_LEN_BUF 1000
  1480.  
  1481. static char yytext[MAX_LEN_BUF];
  1482. static int lexstate;
  1483. static int nextchar;
  1484.  
  1485.  
  1486. static void
  1487. lexinit()
  1488.  
  1489. {
  1490.     lexstate = LEX_START;
  1491.     nextchar = getc(yyin);
  1492. }
  1493.  
  1494. isextdigit(c)
  1495.  
  1496. char c;
  1497.  
  1498. {
  1499.     return((c == 'e') || (c == 'E') || (c == '+') || (c == '-') || isdigit(c));
  1500. }
  1501.  
  1502. iswhite(c)
  1503.  
  1504. char c;
  1505.  
  1506. {
  1507.     if (c == '\n')
  1508.     {
  1509.         line_no++;
  1510.         return(TRUE);
  1511.     }
  1512.     else
  1513.     {
  1514.         return((c == 0) || (c == ' ') || (c == '\t'));
  1515.     }
  1516. }
  1517.  
  1518. static int
  1519. gettoken(str)
  1520.  
  1521. char *str;
  1522.  
  1523. {
  1524.  
  1525.     int i;
  1526.     int outcode;
  1527.  
  1528.     static struct tok
  1529.     {
  1530.         char *token;
  1531.         int code;
  1532.     } toktab[] =
  1533.     {
  1534.         "function"    , FUNCTION,
  1535.         "dimension"   , DIMENSIONS,
  1536.         "dimensions"  , DIMENSIONS,
  1537.         "="           , EQUALS,
  1538.         "quantization", QUANTIZATION,
  1539.         ":"           , COLON,
  1540.         "coding"      , CODING,
  1541.         "training"    , TRAINING,
  1542.         "set"         , SET,
  1543.         "size"        , _SIZE,
  1544.         "test"        , TEST,
  1545.         "tree"        , TREE,
  1546.         "minimum"     , MIN,
  1547.         "min"         , MIN,
  1548.         "maximum"     , MAX,
  1549.         "max"         , MAX,
  1550.         "correct"     , CORRECT,
  1551.         "epochs"      , EPOCHS,
  1552.         "largest"     , LARGEST,
  1553.         "smallest"    , SMALLEST,
  1554.         "domain"      , DOMAINS,
  1555.         "codomain"    , CODOMAINS,
  1556.         "vote"        , VOTE,
  1557.         "save"        , SAVE,
  1558.         "to"          , TO,
  1559.         "load"        , LOAD,
  1560.         "from"        , FROM,
  1561.         "folded"      , FOLDED,
  1562.         NULL          ,0
  1563.     };
  1564.  
  1565.     outcode = IDENTIFIER;
  1566.  
  1567.     for (i = 0; toktab[i].token != NULL; i++)
  1568.     {
  1569.         if (strcmp(str,toktab[i].token) == 0)
  1570.         {
  1571.             outcode = toktab[i].code;
  1572.             break;
  1573.         }
  1574.     }
  1575.  
  1576.     return(outcode);
  1577. }
  1578.  
  1579. static int
  1580. yylex()
  1581.  
  1582. {
  1583.     int bufptr;
  1584.     BOOL found_token;
  1585.     int token;
  1586.  
  1587.     found_token = FALSE;
  1588.     bufptr = 0;
  1589.  
  1590.     if (first)
  1591.     {
  1592.         first = FALSE;
  1593.         lexinit();
  1594.     }
  1595.  
  1596.     while (!found_token)
  1597.     {
  1598.         switch (lexstate)
  1599.         {
  1600.             case LEX_START:
  1601.                 while (iswhite(nextchar))
  1602.                 {
  1603.                      nextchar = getc(yyin);
  1604.                 }
  1605.  
  1606.                 if (ISCOMMENT(nextchar))
  1607.                 {
  1608.                     nextchar = getc(yyin);
  1609.                     lexstate = LEX_COMMENT;
  1610.                 }
  1611.                 else if (isdigit(nextchar) || (nextchar == '-'))
  1612.                 {
  1613.                     yytext[bufptr++] = nextchar;
  1614.                     nextchar = getc(yyin);
  1615.                     lexstate = LEX_INT;
  1616.                 }
  1617.                 else if (isalpha(nextchar))
  1618.                 {
  1619.                     yytext[bufptr++] = nextchar;
  1620.                     nextchar = getc(yyin);
  1621.                     lexstate = LEX_IDENT;
  1622.                 }
  1623.                 else if (nextchar == '"')
  1624.                 {
  1625.                     nextchar = getc(yyin);
  1626.                     lexstate = LEX_STRING;
  1627.                 }
  1628.                 else if (ispunct(nextchar))
  1629.                 {
  1630.                     yytext[bufptr++] = nextchar;
  1631.                     nextchar = getc(yyin);
  1632.                     lexstate = LEX_PUNCT;
  1633.                 }
  1634.                 else if (nextchar == EOF)
  1635.                 {
  1636.                     lexstate = LEX_STOP;
  1637.                 }
  1638.                 else
  1639.                 {
  1640.                     wsprintf(szBuffer,
  1641.                                   "unrecognized character '%c', line %d.\n",
  1642.                                    nextchar, line_no);
  1643.                     MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1644.                     yyerrexit();
  1645.                     return(YYEXIT);
  1646.                 }
  1647.                 break;
  1648.  
  1649.             case LEX_INT:
  1650.                 while (isdigit(nextchar))
  1651.                 {
  1652.                     yytext[bufptr++] = nextchar;
  1653.                     nextchar = getc(yyin);
  1654.                 }
  1655.                 if (nextchar == '.')
  1656.                 {
  1657.                     yytext[bufptr++] = nextchar;
  1658.                     nextchar = getc(yyin);
  1659.                     lexstate = LEX_DEC;
  1660.                 }
  1661.                 else
  1662.                 {
  1663.                     yytext[bufptr] = 0;
  1664.                     yylval.i = atoi(yytext);
  1665.                     token = INTEGER;
  1666.                     found_token = TRUE;
  1667.                 }
  1668.                 break;
  1669.  
  1670.             case LEX_DEC:
  1671.                 while (isextdigit(nextchar))
  1672.                 {
  1673.                     yytext[bufptr++] = nextchar;
  1674.                     nextchar = getc(yyin);
  1675.                 }
  1676.                 yytext[bufptr] = 0;
  1677.                 sscanf(yytext,"%g",&yylval.f);
  1678.                 token = REAL;
  1679.                 found_token = TRUE;
  1680.                 break;
  1681.  
  1682.             case LEX_IDENT:
  1683.                 while (isalpha(nextchar) || isdigit(nextchar))
  1684.                 {
  1685.                     yytext[bufptr++] = nextchar;
  1686.                     nextchar = getc(yyin);
  1687.                 }
  1688.                 yytext[bufptr] = 0;
  1689.                 token = gettoken(yytext);
  1690.                 found_token = TRUE;
  1691.                 break;
  1692.  
  1693.             case LEX_STRING:
  1694.                 while (nextchar != '"')
  1695.                 {
  1696.                     if (nextchar == '\n')
  1697.                     {
  1698.                         wsprintf(szBuffer,
  1699.                                        "newline in string, line %d.\n",
  1700.                                        line_no);
  1701.                         MessageBox(NULL, szBuffer, "lf read_prog()", MB_OK | MB_ICONEXCLAMATION);
  1702.                         return (YYEXIT);
  1703.                     }
  1704.                     yytext[bufptr++] = nextchar;
  1705.                     nextchar = getc(yyin);
  1706.                 }
  1707.                 nextchar = getc(yyin); /* skip closing quote */
  1708.                 yytext[bufptr] = 0;
  1709.                 yylval.s = strdup(yytext);
  1710.                 token = STRING;
  1711.                 found_token = TRUE;
  1712.                 break;
  1713.  
  1714.             case LEX_PUNCT:
  1715.                 yytext[bufptr] = 0;
  1716.                 token = gettoken(yytext);
  1717.                 found_token = TRUE;
  1718.                 break;
  1719.  
  1720.             case LEX_COMMENT:
  1721.                 while (nextchar != '\n')
  1722.                 {
  1723.                     nextchar = getc(yyin);
  1724.                 }
  1725.                 lexstate = LEX_START;
  1726.                 break;
  1727.  
  1728.             case LEX_STOP:
  1729.                 token = 0;
  1730.                 found_token = TRUE;
  1731.                 first = TRUE;
  1732.                 break;
  1733.         }
  1734.     }
  1735.  
  1736.     if (lexstate != LEX_STOP)
  1737.     {
  1738.         lexstate = LEX_START;
  1739.     }
  1740.     return(token);
  1741. }
  1742.